﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class Personas : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["CadenaDeConexion"] = ConfigurationManager.ConnectionStrings["RFID"].ConnectionString;
    }
    protected void LinkButtonAddNew_Click(object sender, EventArgs e)
    {
        FormViewPersonas.ChangeMode(FormViewMode.Insert);
    }
    protected void InsertCancelButton_Click(object sender, EventArgs e)
    {
        limpiarFormulario();
    }
    protected void FormViewPersonas_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        limpiarFormulario();
    }
    private void limpiarFormulario()
    {
        GridViewPersonas.SelectedIndex = -1;
        GridViewPerfilesDeUsuario.Visible = false;
        FormViewUsuario.Visible = false;
        GridViewPersonas.DataBind();
        FormViewPersonas.Controls.Clear();
        FormViewPersonas.ChangeMode(FormViewMode.ReadOnly);
    }
    private void limpiarFormularioPerfiles()
    {
        GridViewPersonas.SelectedIndex = -1;
        GridViewPerfilesDeUsuario.Visible = false;
        FormViewUsuario.Visible = false;
        GridViewPersonas.DataBind();
        FormViewPerfilesDeUsuario.Controls.Clear();
        FormViewPerfilesDeUsuario.ChangeMode(FormViewMode.ReadOnly);
    }
    protected void FormViewPersonas_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        limpiarFormulario();
    }
    protected void LinkButtonAddNew_Click1(object sender, EventArgs e)
    {
        FormViewPerfilesDeUsuario.ChangeMode(FormViewMode.Insert);
    }
    protected void FormViewPerfilesDeUsuario_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        limpiarFormularioPerfiles();
    }
    protected void InsertCancelButton_Click1(object sender, EventArgs e)
    {
        limpiarFormularioPerfiles();
    }
    protected void GridViewPersonas_SelectedIndexChanged(object sender, EventArgs e)
    {
        GridViewPerfilesDeUsuario.Visible = true;
        FormViewUsuario.Visible = true;
    }
    protected void FormViewPerfilesDeUsuario_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["Persona"] = GridViewPersonas.SelectedValue.ToString();
    }
    protected void LinkButtonAddNew_Click2(object sender, EventArgs e)
    {
        FormViewUsuario.ChangeMode(FormViewMode.Insert);
    }
    protected void FormViewUsuario_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["Codigo"] = GridViewPersonas.SelectedValue.ToString();
    }
    protected void FormViewUsuario_ItemDeleting(object sender, FormViewDeleteEventArgs e)
    {
        e.Values["Codigo"] = GridViewPersonas.SelectedValue.ToString();
    }
    protected void ObjectDataSourcePersona_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
    {
        LabelEntrada.Text = e.OutputParameters["tipoAcceso"].ToString();
    }
    protected void ObjectDataSourcePersonas_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
    {
        LabelEntrada.Text = e.OutputParameters["mensaje"].ToString();
    }
}
